Delete Data
What does it do?
Removes a single document from the customer-scoped data store by collection + key. If the row doesn't exist or is already expired, the node routes to on_failure.
1. Syntax
<node_name>:
type: func
func_type: dataStorage
func_id: delete
params:
collection: "<collection_name>"
key: "<record_key>"
on_complete: <next_node>
on_failure: <fallback_node>
required params
typetype of the nodefunc_typehere it will bedataStoragefunc_idwhat function are we calling (delete)params.collectioncollection name. Must match^[a-zA-Z0-9_-]+$(letters, digits,_,-), max 100 charsparams.keyrecord key within the collection (non-empty, max 200 chars)on_completenext node after the delete succeeds
optional params
on_failurefallback node — used when the row doesn't exist or is already expireddepartmentassigns the chat to a departmentagentassigns the chat to a specific agent (email address or CRM ID as defined in the Texter agents manager)
2. Output
On success, stored at %state:node.<node_name>%:
{ "deleted": true }
3. Examples
Clear SLA row when chat resolves
clear_sla_record:
type: func
func_type: dataStorage
func_id: delete
params:
collection: "sla_chats"
key: "%chat:channelInfo.id%"
on_complete: resolved_message
on_failure: resolved_message
Delete using a key from user input
remove_draft:
type: func
func_type: dataStorage
func_id: delete
params:
collection: "draft_orders"
key: "%state:node.ask_draft_id.text%"
on_complete: confirm_cancelled
on_failure: draft_not_found
Safely delete only if the record exists (cleanup at start)
When you clean a record at the start of a bot run (e.g. removing a chat from a follow-up campaign once the customer finally replies), guard the delete with a get plus a matchExpression existence check, so delete is only reached when the row is actually there:
check_record:
type: func
func_type: dataStorage
func_id: get
params:
collection: passive_marketing_chats
key: "%chat:_id|toString%"
on_complete: record_exists
record_exists:
type: func
func_type: system
func_id: matchExpression
params:
expression: "exists(entry)"
entry: "%state:node.check_record%"
on_complete: delete_record
on_failure: continue_normally
delete_record:
type: func
func_type: dataStorage
func_id: delete
params:
collection: passive_marketing_chats
key: "%chat:_id|toString%"
on_complete: continue_normally
Calling delete on a missing or expired row raises an error, and without an on_failure that error leaves the bot stuck on the node. The existence check above avoids calling delete at all when there is nothing to remove. Note the %chat:_id|toString% key: the chat _id is a Mongo ObjectId and must be passed through |toString (see Overview).
Always set on_failure — delete raises an error when the row is missing or expired. If you don't care about that case (e.g. you just want to make sure it's gone), point on_failure at the same node as on_complete.